﻿using Decision.athen;
using Decision.BusinessLayer;
using Decision.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using thaihua.service;

public partial class register : System.Web.UI.Page
{
    private static readonly int STATUS_SUCCESS = 2;
    private static readonly int STATUS_DISABLED = -1;
    private static readonly string STATUS_ACTIVE = "1,2";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
        }
    }

    private void InitPage()
    {
        BindDropDownList();
        InitValue();

        //TODO:
        try
        {
            ddl_LAWYER_ID.SelectedValue = UserAthen.UserLogin.USER_ID + "";
        }
        catch { }

        SetTab();
        SetPermission();
    }

    private void SetPermission()
    {
        //TODO:
        if (Request.QueryString["masterID"] != null)
        {
            int masterId = int.Parse(Request.QueryString["masterID"]);
            RenderEdit(masterId);
        }
    }

    private void InitStep1()
    {
        List<DCS_STEP_01> listStep01 = DCSFactory.CreateDCS_STEP_01Factory().GetAllBy(DCS_STEP_01.DCS_STEP_01Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        if (listStep01.Count > 0)
        {
            Util.FillInFormTo(listStep01[0], Util.GetControlFrom(viewDep1), false);

            if (listStep01[0].STATUS == null || listStep01[0].STATUS != 2)
            {
                chk011_Status.ToggleStates[0].Selected = true;
            }
            else
            {
                chk011_Status.ToggleStates[1].Selected = true;
            }
        }
        else
        {
            chk011_Status.ToggleStates[0].Selected = true;
        }
    }

    private void SetTab()
    {
        if (Request.QueryString["masterID"] != null)
        {
            RadTabStrip1.SelectedIndex = 1;
            RadTabStrip1.Tabs[1].Selected = true;
            RadMultiPage1.SelectedIndex = 1;

            try
            {
                RenderStep((Request.QueryString["masterID"]));
            }
            catch
            {
                Util.jsAlert(Page, "URL ไม่ถูกต้อง");
                return;
            }
            InitStep1();
        }
    }

    protected override void OnInit(EventArgs e)
    {
        InitValidation();
        base.OnInit(e);
    }

    private void InitValue()
    {
        rd_NOTICE_before.Checked = true;
        rd_NOTICE_after.Checked = false;
        IList<RadComboBoxItem> listItem = ddl_DECISION_TYPE_ID.CheckedItems;

        foreach (RadComboBoxItem rd in listItem)
        {
            rd.Checked = false;
        }

        txt_listDecision.Text = "";
        tr_choose.Visible = false;

        BindingVoteType();

        rd_NOTICE_after_CheckedChanged(null, null);
    }

    /// <summary>
    /// Init Validate RequireField in Controll
    /// </summary>
    private void InitValidation()
    {
        //Validation.ValidateRequiredField(ref Panel1, new Control[] { txt_CODE_NO, cal_SIGN_DATE }, Constant.VALIDATE_GROUP_SUBMIT, false);
        Validation.ValidateRequiredField(ref PanelSearch, new Control[] { txt_SearchVale }, Constant.VALIDATE_GROUP_SEARCH);

        ddl_CASE_TYPE_IDValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        ddl_CASE_TYPE_IDValidator.ValueToCompare = Constant.REQ_FEILD;
        ddl_CASE_TYPE_IDValidator.Operator = ValidationCompareOperator.NotEqual;
        ddl_CASE_TYPE_IDValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        ddl_DECISION_TYPE_IDFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        ddl_DECISION_TYPE_IDFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        txt_CODE_NOFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        txt_CODE_NOFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        lb_DECISION_NOFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_EDIT;
        lb_DECISION_NOFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        //cal_SIGN_DATEFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        //cal_SIGN_DATEFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        cal_CREATE_DECISION_DATEFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        cal_CREATE_DECISION_DATEFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        ddl_RESULT_TYPEFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        ddl_RESULT_TYPEFieldValidator.ValueToCompare = Constant.REQ_FEILD;
        ddl_RESULT_TYPEFieldValidator.Operator = ValidationCompareOperator.NotEqual;
        ddl_RESULT_TYPEFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        ddl_VOTE_TYPE_IDFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        ddl_VOTE_TYPE_IDFieldValidator.ValueToCompare = Constant.REQ_FEILD;
        ddl_VOTE_TYPE_IDFieldValidator.Operator = ValidationCompareOperator.NotEqual;
        ddl_VOTE_TYPE_IDFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        DDL_DCS_MEMBER_TYPECompareValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        DDL_DCS_MEMBER_TYPECompareValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        DDL2_PROVINCECompareValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        DDL2_PROVINCECompareValidator.ValueToCompare = Constant.REQ_FEILD;
        DDL2_PROVINCECompareValidator.Operator = ValidationCompareOperator.NotEqual;
        DDL2_PROVINCECompareValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        DDL_PROVINCECompareValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        DDL_PROVINCECompareValidator.ValueToCompare = Constant.REQ_FEILD;
        DDL_PROVINCECompareValidator.Operator = ValidationCompareOperator.NotEqual;
        DDL_PROVINCECompareValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        //ddl_LAWYER_IDCompareValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        //ddl_LAWYER_IDCompareValidator.ValueToCompare = Constant.REQ_FEILD;
        //ddl_LAWYER_IDCompareValidator.Operator = ValidationCompareOperator.NotEqual;
        //ddl_LAWYER_IDCompareValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

        //CAL_RESULT_DATERequiredFieldValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
        //CAL_RESULT_DATERequiredFieldValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;

    }

    /// <summary>
    /// Data Binding Dropdown
    /// </summary>
    private void BindDropDownList()
    {
        DropDownStaticFactory.GetSearchBy(ref ddl_searchBy, false);
        DropDownStaticFactory.GetCaseType(ref ddl_CASE_TYPE_ID, true);
        DropDownStaticFactory.GetVoteType(ref ddl_VOTE_TYPE_ID, true);
        DropDownStaticFactory.GetResultType(ref ddl_RESULT_TYPE, true);
        DropDownStaticFactory.GetLawyer(ref ddl_LAWYER_ID, true);
        DropDownStaticFactory.GetLawyer(ref ddl2_LAWYER_ID, true);
        DropDownStaticFactory.GetDecisionType(ref ddl_DECISION_TYPE_ID, false);
        DropDownStaticFactory.GetProvince(ref DDL_PROVINCE, true);
        DropDownStaticFactory.GetMemberType(ref DDL_DCS_MEMBER_TYPE, false);
        DropDownStaticFactory.GetCourtConstituType(ref DDL_COURT_CONSTITU_TYPE, false);
        DropDownStaticFactory.GetCourtASupremeType(ref DDL_COURT_B_SUPREME_TYPE_ID, false);
        DropDownStaticFactory.GetCourtASupremeType(ref DDL_COURT_A_SUPREME_TYPE_ID, false);
        DropDownStaticFactory.GetCOURT(ref ddl7_SIGN_CASE_TYPE_ID, false);
        DropDownStaticFactory.GetProvince(ref ddl7_PROVINCE, false);
        DropDownStaticFactory.GetProvince(ref ddl14_PROVINCE, false);
        DropDownStaticFactory.GetProvince(ref DDL2_PROVINCE, true);
        DropDownStaticFactory.GetCourtAppType(ref DDL_COURT_APPEALS_TYP_ID, false);
        DropDownStaticFactory.GetINJUNCTION_COURT(ref ddl_INJUNCTION_COURT_ID, true);
    }

    protected void RenderEdit(int masterId)
    {
        if (UserAthen.UserLogin.USER_GROUP_LVL == UserAthen.ADMIN)
        {
            bt_Edit.Visible = true;
            return;
        }

        DCS_MASTER dto = DCSFactory.CreateDCSMasterFactory().GetByPrimaryKey(new DCS_MASTERKeys(masterId));

        if (dto != null && dto.CREATED_USER == UserAthen.UserLogin.USER_ID)
        {
            bt_Edit.Visible = true;
            return;
        }
    }

    protected Boolean RenderEdit(Object status)
    {
        if (UserAthen.UserLogin.USER_GROUP_LVL == UserAthen.ADMIN)
        {
            return true;
        }

        if (UserAthen.UserLogin.USER_GROUP_LVL == UserAthen.MANAGER)
        {
            return false;
        }

        return status == null || status.ToString() == "" || ((int)status) != 2;
    }

    protected Boolean RenderView(Object status)
    {
        return UserAthen.UserLogin.USER_GROUP_LVL == UserAthen.MANAGER;
    }

    protected void Edit(object sender, EventArgs e)
    {
        if (ProcessEdit())
        {
            Util.jsAlert(JSUpdate, Constant.SAVE_SUCESS);
            return;
        }
        else
        {
            Util.jsAlert(JSUpdate, Constant.SAVE_NOT_SUCESS);
            return;
        }
    }

    protected void Save(object sender, EventArgs e)
    {

        //Check Dupp Code No
        if (IsDuppCodeNo(txt_CODE_NO.Text))
        {
            //Is Dupp
            Util.jsAlert(JSUpdate, string.Format(Constant.PRODUCT_DUPP, "เลขที่ใช้ค้นหาข้อมูล"));
            return;
        }

        if (ProcessSave())
        {
            Util.jsAlert(JSUpdate, Constant.SAVE_SUCESS);
            return;
        }
        else
        {
            Util.jsAlert(JSUpdate, Constant.SAVE_NOT_SUCESS);
            return;
        }
    }

    protected void Reset(object sender, EventArgs e)
    {
        //Util.ResetForm(Util.GetControlFrom(Panel1));
        InitValue();
        Util.jsRedirect(JSUpdate, "");
    }

    /// <summary>
    ///Check Dupp Code No
    /// </summary>
    /// <param name="codeNO"></param>
    /// <returns></returns>
    private bool IsDuppCodeNo(string codeNO)
    {
        return DCSFactory.CreateDCSMasterFactory().GetAllBy(DCS_MASTER.DCS_MASTERFields.CODE_NO, codeNO).Count > 0;
    }

    private bool ProcessEdit()
    {
        try
        {
            DCS_MASTER dto = DCSFactory.CreateDCSMasterFactory().GetByPrimaryKey(new DCS_MASTERKeys(int.Parse(hd_MASTER_ID.Value)));
            dto.LAWYER_ID = int.Parse(ddl2_LAWYER_ID.SelectedValue);
            dto.REMARK = txt2_Remark.Text;
            dto.DECISION_NO = lb_DECISION_NO.Text;
            DCSFactory.CreateDCSMasterFactory().Update(dto);

            Save_DCS_STEP_01(dto.MASTER_ID);
            return true;
        }
        catch (Exception ex)
        {
            return false;
        }
    }

    /// <summary>
    /// Save Data
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private bool ProcessSave()
    {
        try
        {
            DCS_MASTER dto = new DCS_MASTER();
            Util.FillInFormTo(dto, Util.GetControlFrom(Panel1), true);
            dto.NOTICE = rd_NOTICE_before.Checked ? 1 : 2;
            dto.VOTE_CASE = RD_VOTE_CASE1.Checked ? 1 : 2;
            //Should be null when init
            dto.COURT_APPEALS_ID = null;

            //เลือกไปศาล
            if (ddl_RESULT_TYPE.SelectedValue == "1")
            {
                //ประเภทศาล
                if (RD_COURT_TYPE_ID1.Checked)
                {
                    dto.COURT_TYPE_ID = 1;
                    dto.COURT_B_SUPREME_TYPE_ID = int.Parse(DDL_COURT_B_SUPREME_TYPE_ID.SelectedValue);
                    dto.COURT_APPEALS_ID = int.Parse(DDL_COURT_APPEALS_TYP_ID.SelectedValue);
                }
                else if (RD_COURT_TYPE_ID2.Checked)
                {
                    dto.COURT_TYPE_ID = 2;
                    dto.COURT_A_SUPREME_TYPE_ID = int.Parse(DDL_COURT_A_SUPREME_TYPE_ID.SelectedValue);
                }
                else if (RD_COURT_TYPE_ID3.Checked)
                {
                    dto.COURT_TYPE_ID = 3;
                    dto.COURT_CONSTITU_TYPE = int.Parse(DDL_COURT_CONSTITU_TYPE.SelectedValue);
                }
            }
            //กำหนดวันแจ้งเตือนเพิ่มจากวันลงวันที่ไป20วัน
            if (cal_SIGN_DATE.SelectedDate != null)
            {
                dto.WARN_SIGN_DATE = ((DateTime)cal_SIGN_DATE.SelectedDate).AddDays(20);
            }
            //กำหนดวันแจ้งเตือนเพิ่มจากวันประกาศผลไป11เดือน
            if (CAL_RESULT_DATE.SelectedDate != null)
            {
                dto.WARN_RESULT_DATE = ((DateTime)CAL_RESULT_DATE.SelectedDate).AddMonths(11);
            }
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            dto.CREATED_DATE_TIME = DateTime.Now;

            //เลือกอื่นๆ
            if (IsEctItem())
            {
                dto.DECISION_TYPE_ETC = txt_DECISION_TYPE_ETC.Text;
            }

            DCSFactory.CreateDCSMasterFactory().InsertDcsMasterTransaction(dto, GetListDecisionType());

            //ddl_VOTE_TYPE_ID = 3 Save DCS_MASTER_MEMBER
            if (ddl_VOTE_TYPE_ID.SelectedValue == "3")
            {
                List<DCS_MASTER_MEMBER> list = GetListMasterMemberType(dto.MASTER_ID);
                foreach (DCS_MASTER_MEMBER obj in list)
                {
                    DCSFactory.CreateDCS_MASTER_MEMBERFactory().Insert(obj);
                }
            }


            Save_DCS_STEP_01(dto.MASTER_ID);

            return true;
        }
        catch (Exception ex)
        {
            Util.jsConsole(JSUpdate, ex);
            return false;
        }
    }

    /// <summary>
    /// Get List Decision from Dropdown
    /// </summary>
    /// <returns></returns>
    private List<TBL_DCS_MASTER_DECISION_TYPE> GetListDecisionType()
    {
        List<TBL_DCS_MASTER_DECISION_TYPE> listMasterDecisionType = new List<TBL_DCS_MASTER_DECISION_TYPE>();
        IList<RadComboBoxItem> listItem = ddl_DECISION_TYPE_ID.CheckedItems;

        foreach (RadComboBoxItem rb in listItem)
        {
            listMasterDecisionType.Add(new TBL_DCS_MASTER_DECISION_TYPE { DECISION_TYPE_ID = int.Parse(rb.Value) });
        }

        return listMasterDecisionType;
    }

    private List<DCS_MASTER_MEMBER> GetListMasterMemberType(int masterID)
    {
        List<DCS_MASTER_MEMBER> listMasterMember = new List<DCS_MASTER_MEMBER>();
        IList<RadComboBoxItem> listItem = DDL_DCS_MEMBER_TYPE.CheckedItems;

        foreach (RadComboBoxItem rb in listItem)
        {
            listMasterMember.Add(new DCS_MASTER_MEMBER { MASTER_ID = masterID, MEMBER_TYPE_ID = int.Parse(rb.Value) });
        }

        return listMasterMember;
    }

    private void LoadDCSMaster()
    {
        //Validate must not be empty
        if (txt_SearchVale.Text.Trim() == "")
        {
            return;
        }

        string field = ddl_searchBy.SelectedValue;
        string value = txt_SearchVale.Text;

        QueryMasTerDataCriteria criteria = null;

        if (UserAthen.ADMIN == UserAthen.UserLogin.USER_GROUP_LVL || UserAthen.MANAGER == UserAthen.UserLogin.USER_GROUP_LVL)
        {
            criteria = new QueryMasTerDataCriteria
            {
                //Criteria
                Field = field,
                Value = value,
                StatusID = STATUS_ACTIVE
            };
        }
        else
        {
            criteria = new QueryMasTerDataCriteria
            {
                //Criteria
                Field = field,
                Value = value,
                StatusID = STATUS_ACTIVE
                //,CreatedUser = UserAthen.UserLogin.USER_ID
            };
        }
        List<QueryMasTerData> listDCSMaster = DCSFactory.CreateQueryMasTerDataFactory().SelectByBusinessObject(criteria);

        GridResult.VirtualItemCount = listDCSMaster.Count;
        GridResult.DataSource = listDCSMaster;
        GridResult.DataBind();
    }

    /// <summary>
    /// Search By Criteria
    /// </summary>
    /// <param name="field"></param>
    /// <param name="value"></param>
    /// <returns></returns>
    private List<QueryMasTerData> FindQueryMasterDataByCriteria(string field, string value)
    {
        return DCSFactory.CreateQueryMasTerDataFactory().SelectByBusinessObject(new QueryMasTerDataCriteria
        {
            //Criteria
            Field = field,
            Value = value
        });
    }

    protected string iconName(string status)
    {
        return status;
    }

    protected void ddl_listDecisions_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        txt_listDecision.Text = "";
        txt_listDecision.Rows = 0;

        RadComboBox rb = (RadComboBox)sender;

        //Items should be not empty
        if (rb.Items == null || rb.Items.Count == 0)
        {
            tr_choose.Visible = false;
            return;
        }

        foreach (RadComboBoxItem item in rb.Items)
        {
            if (item.Checked)
            {
                txt_listDecision.Text += item.Text + "\n";
                txt_listDecision.Rows += 1;
            }
        }

        TR_DECISION_TYPE_ETC.Visible = IsEctItem();

        //Hide tr if unselect all item
        tr_choose.Visible = txt_listDecision.Rows != 0;
    }

    private bool IsEctItem()
    {
        RadComboBoxItem rb = ddl_DECISION_TYPE_ID.Items.FindItemByValue("19");
        return rb != null && rb.Checked;
    }

    protected void bt_searchBy_Click(object sender, EventArgs e)
    {
        LoadDCSMaster();
        OpenPopup();
    }
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        LoadDCSMaster();
    }

    /// <summary>
    /// Row select on dataGrid select Search reseult
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void SelectRow(object sender, EventArgs e)
    {
        //SelectRow MASTER_ID
        string masterID = ((RadButton)sender).CommandArgument;

        //Render Table Detail and Table Step
        RenderStep(masterID);

        //Render Step1
        InitStep1();

        //Set Permission for edit button
        RenderEdit(int.Parse(masterID));
    }

    /// <summary>
    /// Rows Delete
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DeleteRow(object sender, EventArgs e)
    {
        //SelectRow MASTER_ID
        string masterID = ((RadButton)sender).CommandArgument;

        //Select dto before update
        DCS_MASTER dto = DCSFactory.CreateDCSMasterFactory().GetByPrimaryKey(new DCS_MASTERKeys(int.Parse(masterID)));

        //Update status to Disable
        dto.STATUS = STATUS_DISABLED;
        //bool deleted = DCSFactory.CreateDCSMasterFactory().Update(dto);

        bool deleted = DCSFactory.CreateDCSMasterFactory().Delete(new DCS_MASTERKeys(int.Parse(masterID)));

        Util.jsAlert(JSUpdate, deleted ? Constant.ITEM_CANCEL : Constant.ITEM_CANCEL_FAIL);

        //ClosePopup
        ClosePopup();
    }


    private void RenderStep(string masterID)
    {
        //PnResultSelect
        PnResultSelect.Visible = true;

        //Expect should have data
        QueryMasTerData data = FindQueryMasterDataByCriteria("MASTER_ID", masterID)[0];
        //Find list Decision and save to view state
        ListDecisionResult = DCSFactory.CreateQueryMasTer_DECISIONFactory().SelectByBusinessObject(new QueryMasTer_DECISIONCriteria
        {
            MASTER_ID = data.MASTER_ID
        });

        if (ListDecisionResult != null)
        {
            for (int i = 0; i < ListDecisionResult.Count; i++)
            {
                //อื่นๆ
                if (ListDecisionResult[i].DECISION_TYPE_ID == 19)
                {
                    DCS_MASTER pk = DCSFactory.CreateDCSMasterFactory().GetByPrimaryKey(new DCS_MASTERKeys(int.Parse(masterID)));
                    if (pk != null)
                    {
                        ListDecisionResult[i].DECISION_NAME += (" :" + pk.DECISION_TYPE_ETC);
                    }
                }
            }
        }

        rp_Decision.DataSource = ListDecisionResult;
        rp_Decision.DataBind();

        //TODO: สมาชิกสภาท้องถิ่นหรือผู้บริหารท้องถิ่น should hide แบบ
        bool isVoteType3 = data.VOTE_TYPE_ID == 3;

        if (isVoteType3)
        {
            TR_VOTE_CASE_NAME.Visible = !isVoteType3;
        }
        else 
        {
            TR_VOTE_CASE_NAME.Visible = isVoteType3;
        }

        tr2_choose_master_type.Visible = isVoteType3;

        bool isVoteType1 = data.VOTE_TYPE_ID == 1;
        TR_COUNTY_NO.Visible = isVoteType1;

        //Fill value to table
        Util.FillInFormTo(data, Util.GetControlFrom(PnResultSelect), false);


        //Reder List DCS_MASTER_MEMBER ประเภืสภาท้องถิ่น
        if (isVoteType3)
        {
            List<DCS_MASTER_MEMBER> listMasterMember = DCSFactory.CreateDCS_MASTER_MEMBERFactory().GetAllBy(DCS_MASTER_MEMBER.DCS_MASTER_MEMBERFields.MASTER_ID, masterID);

            lb_choose_master_type.Text = "";

            foreach (DCS_MASTER_MEMBER item in listMasterMember)
            {
                //item.MEMBER_TYPE_ID
                foreach (RadComboBoxItem i in DDL_DCS_MEMBER_TYPE.Items)
                {
                    if (Convert.ToString(item.MEMBER_TYPE_ID) == i.Value)
                    {
                        lb_choose_master_type.Text += i.Text + "<br/>";
                    }
                }
            }
        }

        //Set Hidden field
        hd_MASTER_ID.Value = masterID;

        //Check RESULT_TYPE รายละเอียดมติ 1 = ไปศาล 2 = ไม่ไปศาล
        //var resultTypeAre2 = new[]{1,2,3,4,5,15};
        DataTable listStep = data.RESULT_TYPE == null || data.RESULT_TYPE == 1 ? DropDownStaticFactory.GetViewStepStatus(masterID, "2,3,4,5,6,7,8,9,10,11,12,13,14,15") : DropDownStaticFactory.GetViewStepStatus(masterID, "2,3,4,5,15");

        GridManageDecision.VirtualItemCount = listStep.Rows.Count;
        GridManageDecision.DataSource = listStep;
        GridManageDecision.DataBind();

        ClosePopup();
    }

    /// <summary>
    /// Event when init open popup
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void InitPopupDecision(object sender, EventArgs e)
    {
        //Get Permission for Manager role can view only
        bool isManager = UserAthen.UserLogin.USER_GROUP_LVL == UserAthen.MANAGER;

        string id = ((RadButton)sender).CommandArgument;

        Control[] cs = null;

        if (id == "1")
        {
            //Load Init data
            List<DCS_STEP_01> listStep01 = DCSFactory.CreateDCS_STEP_01Factory().GetAllBy(DCS_STEP_01.DCS_STEP_01Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);

            cs = Util.GetControlFrom(popUpDep1);

            if (listStep01.Count > 0)
            {
                Util.FillInFormTo(listStep01[0], cs, false);
            }
            else
            {
                chk01_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup1.ClientID);
        }
        else if (id == "2")
        {
            //Load Init data
            List<DCS_STEP_02> listStep02 = DCSFactory.CreateDCS_STEP_02Factory().GetAllBy(DCS_STEP_02.DCS_STEP_02Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);

            cs = Util.GetControlFrom(popUpDep2);

            if (listStep02.Count > 0)
            {
                Util.FillInFormTo(listStep02[0], Util.GetControlFrom(popUpDep2), false);
            }
            else
            {
                chk02_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup2.ClientID);
        }
        else if (id == "3")
        {
            //Load Init data
            List<DCS_STEP_03> listStep03 = DCSFactory.CreateDCS_STEP_03Factory().GetAllBy(DCS_STEP_03.DCS_STEP_03Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);

            cs = Util.GetControlFrom(popUpDep3);

            if (listStep03.Count > 0)
            {
                Util.FillInFormTo(listStep03[0], Util.GetControlFrom(popUpDep3), false);
            }
            else
            {
                chk03_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup3.ClientID);
        }
        else if (id == "4")
        {
            //Load Init data
            List<DCS_STEP_04> listStep04 = DCSFactory.CreateDCS_STEP_04Factory().GetAllBy(DCS_STEP_04.DCS_STEP_04Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);

            cs = Util.GetControlFrom(popUpDep4);

            if (listStep04.Count > 0)
            {
                Util.FillInFormTo(listStep04[0], Util.GetControlFrom(popUpDep4), false);
            }
            else
            {
                chk04_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup4.ClientID);
        }
        else if (id == "5")
        {
            //Load Init data
            List<DCS_STEP_05> listStep05 = DCSFactory.CreateDCS_STEP_05Factory().GetAllBy(DCS_STEP_05.DCS_STEP_05Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep05.Count > 0)
            {
                Util.FillInFormTo(listStep05[0], Util.GetControlFrom(popUpDep5), false);
            }
            else
            {
                chk05_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup5.ClientID);
        }
        else if (id == "6")
        {
            //Load Init data
            List<DCS_STEP_06> listStep06 = DCSFactory.CreateDCS_STEP_06Factory().GetAllBy(DCS_STEP_06.DCS_STEP_06Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep06.Count > 0)
            {
                Util.FillInFormTo(listStep06[0], Util.GetControlFrom(popUpDep6), false);
            }
            else
            {
                chk06_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup6.ClientID);
        }
        else if (id == "7")
        {
            //Load Init data
            List<DCS_STEP_07> listStep07 = DCSFactory.CreateDCS_STEP_07Factory().GetAllBy(DCS_STEP_07.DCS_STEP_07Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep07.Count > 0)
            {
                Util.FillInFormTo(listStep07[0], Util.GetControlFrom(popUpDep7), false);
            }
            else
            {
                chk07_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup7.ClientID);
        }
        else if (id == "8")
        {
            //Load Init data
            List<DCS_STEP_08> listStep08 = DCSFactory.CreateDCS_STEP_08Factory().GetAllBy(DCS_STEP_08.DCS_STEP_08Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep08.Count > 0)
            {
                Util.FillInFormTo(listStep08[0], Util.GetControlFrom(popUpDep8), false);
            }
            else
            {
                chk08_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup8.ClientID);
        }
        else if (id == "9")
        {
            //Load Init data
            List<DCS_STEP_09> listStep09 = DCSFactory.CreateDCS_STEP_09Factory().GetAllBy(DCS_STEP_09.DCS_STEP_09Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep09.Count > 0)
            {
                Util.FillInFormTo(listStep09[0], Util.GetControlFrom(popUpDep9), false);
            }
            else
            {
                chk09_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup9.ClientID);
        }
        else if (id == "10")
        {
            //Load Init data
            List<DCS_STEP_10> listStep10 = DCSFactory.CreateDCS_STEP_10Factory().GetAllBy(DCS_STEP_10.DCS_STEP_10Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep10.Count > 0)
            {
                Util.FillInFormTo(listStep10[0], Util.GetControlFrom(popUpDep10), false);
            }
            else
            {
                chk10_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup10.ClientID);
        }
        else if (id == "11")
        {
            //Load Init data
            List<DCS_STEP_11> listStep11 = DCSFactory.CreateDCS_STEP_11Factory().GetAllBy(DCS_STEP_11.DCS_STEP_11Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep11.Count > 0)
            {
                Util.FillInFormTo(listStep11[0], Util.GetControlFrom(popUpDep11), false);
            }
            else
            {
                chk11_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup11.ClientID);
        }
        else if (id == "12")
        {
            //Load Init data
            List<DCS_STEP_12> listStep12 = DCSFactory.CreateDCS_STEP_12Factory().GetAllBy(DCS_STEP_12.DCS_STEP_12Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep12.Count > 0)
            {
                Util.FillInFormTo(listStep12[0], Util.GetControlFrom(popUpDep12), false);
            }
            else
            {
                chk12_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup12.ClientID);
        }
        else if (id == "13")
        {
            //Load Init data
            List<DCS_STEP_13> listStep13 = DCSFactory.CreateDCS_STEP_13Factory().GetAllBy(DCS_STEP_13.DCS_STEP_13Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep13.Count > 0)
            {
                Util.FillInFormTo(listStep13[0], Util.GetControlFrom(popUpDep13), false);
            }
            else
            {
                chk13_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup13.ClientID);
        }
        else if (id == "14")
        {
            //Load Init data
            ddl_INJUNCTION_COURT_ID.SelectedIndex = 0;
            List<DCS_STEP_14> listStep14 = DCSFactory.CreateDCS_STEP_14Factory().GetAllBy(DCS_STEP_14.DCS_STEP_14Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep14.Count > 0)
            {
                Util.FillInFormTo(listStep14[0], Util.GetControlFrom(popUpDep14), false);
                txt_ETC_INJUNCTION_COURT.Text = listStep14[0].ETC_INJUNCTION_COURT;
                pn_INJUNCTION_COURT.Visible = listStep14[0].INJUNCTION_COURT_ID == 8;
            }
            else
            {
                chk14_Status.ToggleStates[0].Selected = true;
            }
            OpenPopup(modalPopup14.ClientID);
        }
        else if (id == "15")
        {
            //Load Init data
            tr_fileUpload.Visible = true;
            pn_fileDownload.Visible = true;
            List<DCS_STEP_15> listStep15 = DCSFactory.CreateDCS_STEP_15Factory().GetAllBy(DCS_STEP_15.DCS_STEP_15Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            if (listStep15.Count > 0)
            {
                Util.FillInFormTo(listStep15[0], Util.GetControlFrom(popUpDep15), false);

                string fileName = Constant.PATH_FILE_UPLOAD + listStep15[0].DOC_NAME;

                //Set mode Edit set link file download
                pn_fileDownload.Visible = true;
                tr_fileUpload.Visible = false;

                lk_FileDownload.Text = listStep15[0].DOC_NAME;
                lk_FileDownload.CommandArgument = listStep15[0].DOC_NAME_PATH == null ? listStep15[0].DOC_NAME : listStep15[0].DOC_NAME_PATH;

                txt15_RECORD_NO.Text = listStep15[0].RECORD_NO;
            }
            else
            {
                chk15_Status.ToggleStates[0].Selected = true;
                pn_fileDownload.Visible = false;
            }
            OpenPopup(modalPopup15.ClientID);
        }

        if (isManager && cs != null)
            Util.DisableControlAndVisbledButton(cs);
    }

    private void OpenPopup(string id)
    {
        Util.jsWriter(JSUpdate, "4324324", "$find('" + id + "').show();");
    }

    private void ClosePopup(string id)
    {
        Util.jsWriter(JSUpdate, "4324324", "$find('" + id + "').close();");

        //FIX after close popup should be refresh DataTable Step
        try
        {
            string masterID = hd_MASTER_ID.Value;

            if (masterID != null)
            {
                RenderStep(masterID);
            }
        }
        catch { }
    }

    private void OpenPopup()
    {
        Util.jsWriter(this.JSUpdate, "2342", "showDialogPopupInitially();");
    }

    private void ClosePopup()
    {
        Util.jsWriter(this.JSUpdate, "2342", "closeDialogInitially();");
    }


    protected void ddl_VOTE_TYPE_ID_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        BindingVoteType();

        if (ddl_VOTE_TYPE_ID.SelectedValue == "3")
        {
            DDL_DCS_MEMBER_TYPECompareValidator.ValidationGroup = Constant.VALIDATE_GROUP_SUBMIT;
            DDL_DCS_MEMBER_TYPECompareValidator.ErrorMessage = Constant.REQ_FEILD_VALIDATE_HTML;
        }
    }

    /// <summary>
    /// Binding VoteType Panel 1,2,3
    /// </summary>
    private void BindingVoteType()
    {
        PN_VOTE_TYPE1_2.Visible = ddl_VOTE_TYPE_ID.SelectedValue == "1" || ddl_VOTE_TYPE_ID.SelectedValue == "2";

        PN_VOTETYPE1.Visible = ddl_VOTE_TYPE_ID.SelectedValue == "1";
        PN_VOTETYPE2.Visible = ddl_VOTE_TYPE_ID.SelectedValue == "2";
        TR_VOTE_TYPE1.Visible = ddl_VOTE_TYPE_ID.SelectedValue == "1";

        PN_VOTE_TYPE3.Visible = ddl_VOTE_TYPE_ID.SelectedValue == "3";
    }

    protected void ddl_VOTE_TYPE_ID_Load(object sender, EventArgs e)
    {
        BindingVoteType();
    }

    protected void ddl_listMasterType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        txt_choose_master_type.Text = "";
        txt_choose_master_type.Rows = 0;

        RadComboBox rb = (RadComboBox)sender;

        //Items should be not empty
        if (rb.Items == null || rb.Items.Count == 0)
        {
            TR_CHOOSE_MASTER_TYPE.Visible = false;
            return;
        }

        foreach (RadComboBoxItem item in rb.Items)
        {
            if (item.Checked)
            {
                txt_choose_master_type.Text += item.Text + "\n";
                txt_choose_master_type.Rows += 1;
            }
        }

        //Hide tr if unselect all item
        TR_CHOOSE_MASTER_TYPE.Visible = txt_choose_master_type.Rows != 0;
    }

    protected void ddl_RESULT_TYPE_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        TR_COURT_TYPE.Visible = ddl_RESULT_TYPE.SelectedValue == "1";
        RD_COURT_TYPE_ID3_CheckedChanged(null, null);
    }

    protected void RD_COURT_TYPE_ID3_CheckedChanged(object sender, EventArgs e)
    {
        TR_LB_COURT_TYPE0.Visible = RD_COURT_TYPE_ID1.Checked;
        TR_COURT_TYPE0.Visible = RD_COURT_TYPE_ID1.Checked;
        //TR_COURT_CONSTITU_TYPE.Visible = RD_COURT_TYPE_ID3.Checked;
        TR_COURT_CONSTITU_TYPE3.Visible = RD_COURT_TYPE_ID3.Checked;

        TR_COURT_CONSTITU_TYPE1.Visible = RD_COURT_TYPE_ID1.Checked;
        TR_COURT_CONSTITU_TYPE2.Visible = RD_COURT_TYPE_ID2.Checked;
    }

    protected void rd_NOTICE_after_CheckedChanged(object sender, EventArgs e)
    {
        lb_alert.Text = rd_NOTICE_before.Checked ? "<font color='red'>กำหนดวันแจ้งเตือนคือวันที่ </font>" : "";
        lb_alert2.Text = rd_NOTICE_after.Checked ? "<font color='red'>กำหนดวันแจ้งเตือนคือวันที่ </font>" : "";
    }
    protected void GridResultDmin_PageIndexChanged(object sender, GridPageChangedEventArgs e)
    {
        GridResult.CurrentPageIndex = e.NewPageIndex;
        GridResult.DataSource = ListDecisionResult;
        GridResult.VirtualItemCount = ListDecisionResult.Count;
        GridResult.DataBind();
    }
    protected void GridResultADmin_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
    {
        GridResult.CurrentPageIndex = 0;
        GridResult.DataSource = ListDecisionResult;
        GridResult.VirtualItemCount = ListDecisionResult.Count;
        GridResult.DataBind();
    }

    public List<QueryMasTer_DECISION> ListDecisionResult
    {
        get
        {
            return ViewState["_listDecisionResult"] != null ? (List<QueryMasTer_DECISION>)ViewState["_listDecisionResult"] : new List<QueryMasTer_DECISION>();
        }
        set
        {
            ViewState["_listDecisionResult"] = value;

        }
    }
    protected void Save_DCS_STEP_01(int? hd_MASTER_ID)
    {
        List<DCS_STEP_01> listStep01 = DCSFactory.CreateDCS_STEP_01Factory().GetAllBy(DCS_STEP_01.DCS_STEP_01Fields.DCS_MASTER_ID, hd_MASTER_ID);
        DCS_STEP_01 dto = new DCS_STEP_01
        {
            ACTION1_DATE = cal_ACTION1_DATE.SelectedDate,
            ACTION2_DATE = cal_ACTION2_DATE.SelectedDate,
            ACTION3_DATE = cal_ACTION3_DATE.SelectedDate,
            ACTION4_DATE = cal_ACTION4_DATE.SelectedDate,
            REMART1 = txt_REMART1.Text,
            REMART2 = txt_REMART2.Text,
            REMART3 = txt_REMART3.Text,
            REMART4 = txt_REMART4.Text,
            DCS_MASTER_ID = hd_MASTER_ID,
            STATUS = chk01_Status.SelectedToggleStateIndex == 0 ? 0 : 2
        };

        bool isSave = false;

        if (listStep01.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep01[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep01[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_01_ID = listStep01[0].DCS_STEP_01_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_01Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            dto.STATUS = chk011_Status.SelectedToggleStateIndex == 0 ? 0 : 2;
            isSave = DCSFactory.CreateDCS_STEP_01Factory().Insert(dto);
        }

        Util.jsConsole(JSUpdate, "Update step 1 is " + (isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS));
        //ClosePopup(modalPopup1.ClientID);
    }
    protected void Save_DCS_STEP_02(object sender, EventArgs e)
    {
        List<DCS_STEP_02> listStep02 = DCSFactory.CreateDCS_STEP_02Factory().GetAllBy(DCS_STEP_02.DCS_STEP_02Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_02 dto = new DCS_STEP_02
        {
            ACTION_DATE = cal2_ACTION_DATE.SelectedDate,
            REMART = txt2_REMART.Text,
            WARN1_DATE = cal2_WARN1_DATE.SelectedDate,
            WARN2_DATE = cal2_WARN2_DATE.SelectedDate,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk02_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep02.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep02[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep02[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_02_ID = listStep02[0].DCS_STEP_02_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_02Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_02Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup2.ClientID);
    }
    protected void Save_DCS_STEP_03(object sender, EventArgs e)
    {
        List<DCS_STEP_03> listStep03 = DCSFactory.CreateDCS_STEP_03Factory().GetAllBy(DCS_STEP_03.DCS_STEP_03Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_03 dto = new DCS_STEP_03
        {
            ACTION_DATE = cal3_ACTION_DATE.SelectedDate,
            REMART = txt3_REMART.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk03_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep03.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep03[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep03[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_03_ID = listStep03[0].DCS_STEP_03_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_03Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_03Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup3.ClientID);
    }
    protected void Save_DCS_STEP_04(object sender, EventArgs e)
    {
        List<DCS_STEP_04> listStep04 = DCSFactory.CreateDCS_STEP_04Factory().GetAllBy(DCS_STEP_04.DCS_STEP_04Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_04 dto = new DCS_STEP_04
        {
            ACTION_DATE = cal4_ACTION_DATE.SelectedDate,
            REMART = txt4_REMART.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk04_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep04.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep04[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep04[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_04_ID = listStep04[0].DCS_STEP_04_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_04Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_04Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup4.ClientID);
    }
    protected void Save_DCS_STEP_05(object sender, EventArgs e)
    {
        List<DCS_STEP_05> listStep05 = DCSFactory.CreateDCS_STEP_05Factory().GetAllBy(DCS_STEP_05.DCS_STEP_05Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_05 dto = new DCS_STEP_05
        {
            ACTION_DATE = cal5_ACTION_DATE.SelectedDate,
            REMARK = txt5_REMARk.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk05_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep05.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep05[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep05[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_05_ID = listStep05[0].DCS_STEP_05_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_05Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_05Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup5.ClientID);
    }
    protected void Save_DCS_STEP_06(object sender, EventArgs e)
    {
        List<DCS_STEP_06> listStep06 = DCSFactory.CreateDCS_STEP_06Factory().GetAllBy(DCS_STEP_06.DCS_STEP_06Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_06 dto = new DCS_STEP_06
        {
            ACTION_DATE = cal6_ACTION_DATE.SelectedDate,
            REMART = txt6_REMART.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk06_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep06.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep06[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep06[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_06_ID = listStep06[0].DCS_STEP_06_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_06Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_06Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup6.ClientID);
    }
    protected void Save_DCS_STEP_07(object sender, EventArgs e)
    {
        List<DCS_STEP_07> listStep07 = DCSFactory.CreateDCS_STEP_07Factory().GetAllBy(DCS_STEP_07.DCS_STEP_07Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_07 dto = new DCS_STEP_07
        {
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            ACTION_DATE = cal7_ACTION_DATE.SelectedDate,
            CASE_BLACK_NO = txt7_CASE_BLACK_NO.Text,
            PROVINCE = int.Parse(ddl7_PROVINCE.SelectedValue),
            REMARK = txt7_REMARK.Text,
            SIGN_CASE_TYPE_ID = int.Parse(ddl7_SIGN_CASE_TYPE_ID.SelectedValue),
            STATUS = int.Parse(chk07_Status.SelectedToggleState.Value)
        };

        Util.FillInFormTo(dto, Util.GetControlFrom(popUpDep7), false);

        bool isSave = false;

        if (listStep07.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep07[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep07[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_07_ID = listStep07[0].DCS_STEP_07_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_07Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_07Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup7.ClientID);
    }
    protected void Save_DCS_STEP_08(object sender, EventArgs e)
    {
        List<DCS_STEP_08> listStep08 = DCSFactory.CreateDCS_STEP_08Factory().GetAllBy(DCS_STEP_08.DCS_STEP_08Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_08 dto = new DCS_STEP_08
        {
            ACTION_DATE = cal8_ACTION_DATE.SelectedDate,
            REMART = txt8_REMART.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk08_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep08.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep08[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep08[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_08_ID = listStep08[0].DCS_STEP_08_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_08Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_08Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup8.ClientID);
    }
    protected void Save_DCS_STEP_09(object sender, EventArgs e)
    {
        List<DCS_STEP_09> listStep09 = DCSFactory.CreateDCS_STEP_09Factory().GetAllBy(DCS_STEP_09.DCS_STEP_09Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_09 dto = new DCS_STEP_09
        {
            ACTION_DATE = cal9_ACTION_DATE.SelectedDate,
            REMARK = txt9_REMARK.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk09_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep09.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep09[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep09[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_09_ID = listStep09[0].DCS_STEP_09_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_09Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_09Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup9.ClientID);
    }
    protected void Save_DCS_STEP_010(object sender, EventArgs e)
    {
        List<DCS_STEP_10> listStep10 = DCSFactory.CreateDCS_STEP_10Factory().GetAllBy(DCS_STEP_10.DCS_STEP_10Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_10 dto = new DCS_STEP_10
        {
            ACTION_DATE = cal10_ACTION_DATE.SelectedDate,
            REMARK = txt10_REMARK.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk10_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep10.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep10[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep10[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_10_ID = listStep10[0].DCS_STEP_10_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_10Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_10Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup10.ClientID);
    }
    protected void Save_DCS_STEP_011(object sender, EventArgs e)
    {
        List<DCS_STEP_11> listStep11 = DCSFactory.CreateDCS_STEP_11Factory().GetAllBy(DCS_STEP_11.DCS_STEP_11Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_11 dto = new DCS_STEP_11
        {
            ACTION_DATE = cal11_ACTION_DATE.SelectedDate,
            REMARK = txt11_REMARK.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk11_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep11.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep11[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep11[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_11_ID = listStep11[0].DCS_STEP_11_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_11Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_11Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup11.ClientID);
    }
    protected void Save_DCS_STEP_012(object sender, EventArgs e)
    {
        List<DCS_STEP_12> listStep12 = DCSFactory.CreateDCS_STEP_12Factory().GetAllBy(DCS_STEP_12.DCS_STEP_12Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_12 dto = new DCS_STEP_12
        {
            ACTION_DATE = cal12_ACTION_DATE.SelectedDate,
            REMARK = txt12_REMARK.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk12_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep12.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep12[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep12[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_12_ID = listStep12[0].DCS_STEP_12_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_12Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_12Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup12.ClientID);
    }
    protected void Save_DCS_STEP_013(object sender, EventArgs e)
    {
        List<DCS_STEP_13> listStep13 = DCSFactory.CreateDCS_STEP_13Factory().GetAllBy(DCS_STEP_13.DCS_STEP_13Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_13 dto = new DCS_STEP_13
        {
            ACTION_DATE = cal13_ACTION_DATE.SelectedDate,
            REMARK = txt13_REMARK.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk13_Status.SelectedToggleState.Value)
        };

        bool isSave = false;

        if (listStep13.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep13[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep13[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_13_ID = listStep13[0].DCS_STEP_13_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_13Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_13Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup13.ClientID);
    }
    protected void Save_DCS_STEP_014(object sender, EventArgs e)
    {
        List<DCS_STEP_14> listStep14 = DCSFactory.CreateDCS_STEP_14Factory().GetAllBy(DCS_STEP_14.DCS_STEP_14Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_14 dto = new DCS_STEP_14
        {
            ACTION_DATE = cal14_ACTION_DATE.SelectedDate,
            REMARK = txt14_REMARK.Text,
            CASE_RED_NO = txt14_CASE_RED_NO.Text,
            RESULT_CASE = txt14_RESULT_CASE.Text,
            PROVINCE = int.Parse(ddl14_PROVINCE.SelectedValue),
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            STATUS = int.Parse(chk14_Status.SelectedToggleState.Value),
            INJUNCTION_COURT_ID = int.Parse(ddl_INJUNCTION_COURT_ID.SelectedValue),
            ETC_INJUNCTION_COURT = int.Parse(ddl_INJUNCTION_COURT_ID.SelectedValue) == 8 ? txt_ETC_INJUNCTION_COURT.Text : null
        };

        bool isSave = false;

        if (listStep14.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep14[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep14[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_14_ID = listStep14[0].DCS_STEP_14_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_14Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_14Factory().Insert(dto);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup14.ClientID);
    }
    protected void Save_DCS_STEP_015(object sender, EventArgs e)
    {
        //TODO:
        if (!tr_fileUpload.Visible)
        {
            List<DCS_STEP_15> listStep15 = DCSFactory.CreateDCS_STEP_15Factory().GetAllBy(DCS_STEP_15.DCS_STEP_15Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
            DCS_STEP_15 dto = new DCS_STEP_15
            {
                RECORD_NO = txt15_RECORD_NO.Text,
                DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
                DOC_NAME_PATH = DateTime.Now.ToFileTimeUtc() + "",
                STATUS = int.Parse(chk15_Status.SelectedToggleState.Value)
            };

            bool isSave = false;

            dto.CREATED_DATE_TIME = listStep15[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep15[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_15_ID = listStep15[0].DCS_STEP_15_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_15Factory().Update(dto);

            //Update SUCCESS case in Master
            if (isSave && dto.STATUS == STATUS_SUCCESS)
            {
                updateMasterStatus((int)dto.DCS_MASTER_ID, STATUS_SUCCESS);
            }

            Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
            ClosePopup(modalPopup15.ClientID);
        }
    }
    protected void DocUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        UploadedFile file = e.File;

        List<DCS_STEP_15> listStep15 = DCSFactory.CreateDCS_STEP_15Factory().GetAllBy(DCS_STEP_15.DCS_STEP_15Fields.DCS_MASTER_ID, hd_MASTER_ID.Value);
        DCS_STEP_15 dto = new DCS_STEP_15
        {
            RECORD_NO = txt15_RECORD_NO.Text,
            DCS_MASTER_ID = int.Parse(hd_MASTER_ID.Value),
            DOC_NAME_PATH = DateTime.Now.ToFileTimeUtc() + "",
            STATUS = int.Parse(chk15_Status.SelectedToggleState.Value)
        };

        //Check Mode Edit or Insert
        bool isModeInsert = listStep15.Count == 0;

        //Validate before Insert
        if (isModeInsert && file == null)
        {
            Util.jsAlert(JSUpdate, Constant.REQ_FEILD_SELECT + "ไฟล์เอกสารก่อนทำการบันทึก");
            return;
        }

        //For mode insert or mode update when upload new file
        if (isModeInsert || (!isModeInsert && file != null))
        {
            dto.DOC_NAME = file.FileName;
            dto.DOC_TYPE = System.IO.Path.GetExtension(file.FileName);

            string newFullPath = Constant.PATH_FILE_UPLOAD + dto.DOC_NAME_PATH + dto.DOC_TYPE;

            //Delete File before Edit
            if (!isModeInsert)
            {
                deleteFileDownload(Constant.PATH_FILE_UPLOAD + listStep15[0].DOC_NAME_PATH);
            }

            writeFIle(file, newFullPath);


            dto.DOC_NAME_PATH = dto.DOC_NAME_PATH + dto.DOC_TYPE;
        }
        //noting upload
        else
        {
            dto.DOC_NAME = listStep15[0].DOC_NAME;
            dto.DOC_TYPE = listStep15[0].DOC_TYPE;
        }

        bool isSave = false;

        if (listStep15.Count > 0)
        {
            dto.CREATED_DATE_TIME = listStep15[0].CREATED_DATE_TIME;
            dto.CREATED_USER = listStep15[0].CREATED_USER;
            //Call Update
            dto.DCS_STEP_15_ID = listStep15[0].DCS_STEP_15_ID;
            dto.UPDATED_DATE_TIME = DateTime.Now;
            dto.UPDATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_15Factory().Update(dto);
        }
        else
        {
            //Call Insert
            dto.CREATED_DATE_TIME = DateTime.Now;
            dto.CREATED_USER = UserAthen.UserLogin.USER_ID;
            isSave = DCSFactory.CreateDCS_STEP_15Factory().Insert(dto);
        }

        //Update SUCCESS case in Master
        if (isSave && dto.STATUS == STATUS_SUCCESS)
        {
            updateMasterStatus((int)dto.DCS_MASTER_ID, STATUS_SUCCESS);
        }

        Util.jsAlert(JSUpdate, isSave ? Constant.SAVE_SUCESS : Constant.SAVE_NOT_SUCESS);
        ClosePopup(modalPopup15.ClientID);
    }

    /// <summary>
    /// Update Status in MASTER
    /// </summary>
    /// <param name="masterID"></param>
    private void updateMasterStatus(int masterID, int status)
    {
        DCS_MASTER dto = DCSFactory.CreateDCSMasterFactory().GetByPrimaryKey(new DCS_MASTERKeys(masterID));

        dto.STATUS = status;

        DCSFactory.CreateDCSMasterFactory().Update(dto);

    }

    private void writeFIle(UploadedFile file, string newPathNew)
    {
        using (Stream output = File.OpenWrite(newPathNew))
        using (Stream input = file.InputStream)
        {
            input.CopyTo(output);
        }
    }

    private void deleteFileDownload(string fileName)
    {
        if (System.IO.File.Exists(fileName))
        {
            // Use a try block to catch IOExceptions, to 
            // handle the case of the file already being 
            // opened by another process. 
            try
            {
                System.IO.File.Delete(fileName);
            }
            catch (System.IO.IOException e)
            {
                return;
            }
        }
    }

    protected void lk_FileDownload_Click(object sender, EventArgs e)
    {
        string fileName = ((LinkButton)sender).CommandArgument;
        Util.jsRedirect(JSUpdate, "downloads/fileDownload.aspx?fileName=" + fileName);
    }
    protected void NewUpload(object sender, EventArgs e)
    {
        pn_fileDownload.Visible = false;
        tr_fileUpload.Visible = true;
    }
    protected void DDL_PROVINCE_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox rd = (RadComboBox)sender;
        DropDownStaticFactory.GetAmphur(ref ddl_AUMPHER, rd.SelectedValue, true);
    }
    protected void ddl_AUMPHER_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox rd = (RadComboBox)sender;
        DropDownStaticFactory.GetTumbol(ref ddl_TUMBON, rd.SelectedValue, true);
    }

    protected void DDL2_PROVINCE_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox rd = (RadComboBox)sender;
        DropDownStaticFactory.GetAmphur(ref ddl2_AUMPHER, rd.SelectedValue, true);
    }
    protected void ddl2_AUMPHER_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox rd = (RadComboBox)sender;
        DropDownStaticFactory.GetTumbol(ref ddl2_TUMBON, rd.SelectedValue, true);
    }
    protected void ddl_INJUNCTION_COURT_ID_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        pn_INJUNCTION_COURT.Visible = ddl_INJUNCTION_COURT_ID.SelectedValue == "8";
    }
    protected void chk01_Status_CheckedChanged(object sender, EventArgs e)
    {
        //chk01_Status.SelectedToggleStateIndex = chk01_Status.SelectedToggleState.Value == "0"?0:1;
    }
    protected void chk01_Status_Click(object sender, EventArgs e)
    {

    }
}